package su.choco.queuing.domain;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.concurrent.LinkedBlockingQueue;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class Queue {
    int size;
    int capacity;
    String name;
    String description;
    static LinkedBlockingQueue<Item> items;

    static {
        items = new LinkedBlockingQueue<Item>();
    }

    public synchronized boolean enqueue(Item item) {
        if(capacity == size){
            return false;
        }else{
            ++size;
            return items.offer(item);
        }
    }

    public synchronized Item dequeue(){
        if(size == 0){
            return null;
        }else{
            --size;
            return items.poll();
        }
    }
}
